package com.collect.tanzania.zhiScene.zhiCollection.zhiGroup.zhiPerformance.zhiB2;

import android.annotation.SuppressLint;

import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.collect.tanzania.R;
import com.collect.tanzania.zhiBase.BaseActivity;
import com.collect.tanzania.zhiBean.zhiSend.ZHISDailyCaseEntity;
import com.collect.tanzania.zhiBean.zhiSend.ZHISPerfermanceEntity;
import com.collect.tanzania.zhiGlobal.zhiAppSettings.ZHIProjectRouter;
import com.collect.tanzania.zhiScene.zhiCollection.zhiGroup.zhiAccount.ZHIAccountGroupFragment;
import com.collect.tanzania.zhiScene.zhiCollection.zhiGroup.zhiDaily.ZHIDailyGroupFragment;
import com.collect.tanzania.zhiScene.zhiCollection.zhiGroup.zhiPerformance.zhiB1.ZHIPerformanceGroupB1Fragment;
import com.collect.tanzania.zhiScene.zhiCollection.zhiGroup.zhiRoot.ZHIRootGroupFragmentInterface;
import com.collect.tanzania.zhiScene.zhiWidget.zhiNavigationBar.ZHIBottomTabBarItem;

import butterknife.BindView;

@SuppressLint("NonConstantResourceId")
@Route(path = ZHIProjectRouter.ZHI_ROOT_GROUP_B2)
public class ZHIRootGroupB2Activity extends BaseActivity implements ZHIRootGroupFragmentInterface {

    @BindView(R.id.bar_loan)
    ZHIBottomTabBarItem bar_loan;
    @BindView(R.id.bar_account)
    ZHIBottomTabBarItem bar_account;
    @BindView(R.id.bar_perfermance)
    ZHIBottomTabBarItem bar_perfermance;

    private FragmentManager mFragmentManager;
    private ZHIDailyGroupFragment mZHIDailyGroupFragment;
    private ZHIAccountGroupFragment mZHIAccountGroupFragment;

    private ZHIPerformanceGroupB2Fragment mZHIPerformanceGroupB2Fragment;
//    private ZHIPerformanceGroupB1Fragment mZHIPerformanceGroupB2Fragment;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_root_group_b2;
    }

    @Override
    protected void initInjector() {
    }

    @Override
    protected void initView() {
        try {
            mFragmentManager = getSupportFragmentManager();

            initEvent();
            selecFragment(0);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    public void onReloadGroupUserList() {
//        if (drawer_filter_performance != null) {
//            drawer_filter_performance.updateUserDataSource();
//        }
    }

    @Override
    public void onShowFilterDaily() {

    }

    @Override
    public void onShowFilterPerformanceAmount() {
//        if (drawer_filter_performance != null) {
//            drawer_filter_performance.setToTypeMoney();
//            if (drawer_layout.isDrawerOpen(drawer_filter_performance)) {
//                drawer_layout.closeDrawer(drawer_filter_performance);
//            } else {
//                drawer_layout.openDrawer(drawer_filter_performance);
//            }
//        }
    }

    @Override
    public void onShowFilterPerformanceOrder() {
//        if (drawer_filter_performance != null) {
//            drawer_filter_performance.setToTypeOrder();
//            if (drawer_layout.isDrawerOpen(drawer_filter_performance)) {
//                drawer_layout.closeDrawer(drawer_filter_performance);
//            } else {
//                drawer_layout.openDrawer(drawer_filter_performance);
//            }
//        }
    }

    @Override
    public ZHISPerfermanceEntity onGetPerfermanceFilterParams() {
        ZHISPerfermanceEntity zhisPerfermanceEntity = new ZHISPerfermanceEntity();
//        zhisPerfermanceEntity.setLeven(drawer_filter_performance.getLevel());
//        zhisPerfermanceEntity.setEndDate(drawer_filter_performance.getDueEndDate());
//        zhisPerfermanceEntity.setStartDate(drawer_filter_performance.getDudStartDate());
//        zhisPerfermanceEntity.setLeaderUserId(drawer_filter_performance.getMember());
        return zhisPerfermanceEntity;
    }

    @Override
    public ZHISPerfermanceEntity onGetPerfermanceFilterAmountParams() {
        ZHISPerfermanceEntity zhisPerfermanceEntity = new ZHISPerfermanceEntity();
//        zhisPerfermanceEntity.setLeven(drawer_filter_performance.getLevel());
//        zhisPerfermanceEntity.setEndDate(drawer_filter_performance.getDueEndDate());
//        zhisPerfermanceEntity.setStartDate(drawer_filter_performance.getDudStartDate());
//        zhisPerfermanceEntity.setLeaderUserId(drawer_filter_performance.getMember());
        return zhisPerfermanceEntity;
    }

    @Override
    public ZHISPerfermanceEntity onGetPerfermanceFilterOrderParams() {
        ZHISPerfermanceEntity zhisPerfermanceEntity = new ZHISPerfermanceEntity();
//        zhisPerfermanceEntity.setLeven(drawer_filter_performance.getLevel());
//        zhisPerfermanceEntity.setEndDate(drawer_filter_performance.getDueEndDate());
//        zhisPerfermanceEntity.setStartDate(drawer_filter_performance.getDudStartDate());
//        zhisPerfermanceEntity.setLeaderUserId(drawer_filter_performance.getMember());
        return zhisPerfermanceEntity;
    }

    @Override
    public ZHISDailyCaseEntity onGetDailyFilterParams() {
        ZHISDailyCaseEntity zhisDailyCaseEntity = new ZHISDailyCaseEntity();
        return zhisDailyCaseEntity;
    }

    public void initEvent() {
        bar_loan.setCFOnMenuItemDidChangedListener(item -> {
            bar_perfermance.setChecked(false);
            bar_account.setChecked(false);
            selecFragment(0);
        });
        bar_perfermance.setCFOnMenuItemDidChangedListener(item -> {
            bar_loan.setChecked(false);
            bar_account.setChecked(false);
            selecFragment(1);
        });
        bar_account.setCFOnMenuItemDidChangedListener(item -> {
            bar_loan.setChecked(false);
            bar_perfermance.setChecked(false);
            selecFragment(2);
        });
    }

    private void selecFragment(int indext) {
        FragmentTransaction fragemntTransaction = mFragmentManager.beginTransaction();
        hideFragment(fragemntTransaction);
        switch (indext) {
            case 0: {
                bar_loan.setChecked(true);
                bar_perfermance.setChecked(false);
                bar_account.setChecked(false);
                if (null == mZHIDailyGroupFragment) {
                    mZHIDailyGroupFragment = new ZHIDailyGroupFragment();
                    fragemntTransaction.add(R.id.content, mZHIDailyGroupFragment);
                } else {
                    fragemntTransaction.show(mZHIDailyGroupFragment);
                }
                break;
            }
            case 1: {
                bar_loan.setChecked(false);
                bar_perfermance.setChecked(true);
                bar_account.setChecked(false);
                if (null == mZHIPerformanceGroupB2Fragment) {
                    mZHIPerformanceGroupB2Fragment = new ZHIPerformanceGroupB2Fragment();
                    fragemntTransaction.add(R.id.content, mZHIPerformanceGroupB2Fragment);
                } else {
                    fragemntTransaction.show(mZHIPerformanceGroupB2Fragment);
                }
                break;
            }
            case 2: {
                bar_loan.setChecked(false);
                bar_perfermance.setChecked(false);
                bar_account.setChecked(true);
                if (null == mZHIAccountGroupFragment) {
                    mZHIAccountGroupFragment = new ZHIAccountGroupFragment();
                    fragemntTransaction.add(R.id.content, mZHIAccountGroupFragment);
                } else {
                    fragemntTransaction.show(mZHIAccountGroupFragment);
                }
                break;
            }
            default:
                break;
        }
        fragemntTransaction.commit();
    }

    private void hideFragment(FragmentTransaction fragemntTransaction) {
        if (fragemntTransaction == null) return;

        if (null != mZHIDailyGroupFragment) {
            fragemntTransaction.hide(mZHIDailyGroupFragment);
        }
        if (null != mZHIAccountGroupFragment) {
            fragemntTransaction.hide(mZHIAccountGroupFragment);
        }

        if (null != mZHIPerformanceGroupB2Fragment) {
            fragemntTransaction.hide(mZHIPerformanceGroupB2Fragment);
        }
    }
}
